package ygstudio.xue.de;

import java.io.File;

import android.content.Context;
import android.media.MediaPlayer;
import android.os.Environment;

public class RuntimeUtils {
	private static RuntimeUtils runtimeUtils;

	public static RuntimeUtils getInstance() {
		if (runtimeUtils == null) {
			runtimeUtils = new RuntimeUtils();
		}
		return runtimeUtils;
	}

	private MediaPlayer player;
	private String sdAppRootDir;
	private String sdDbDir;
	private String sdDbFile;
	private String sdMp3Dir;

	private String sdRootDir;

	private String sdXmlDir;

	private String sdDefaultXml = "/alles.xml";

	private Context context;

	private RuntimeUtils() {
		init();
	}

	public Context getMainContext() {
		return context;
	}

	public String getSdAppRootDir() {
		return sdAppRootDir;
	}

	public String getSdDbDir() {
		return sdDbDir;
	}

	public String getSdDbFile() {
		return sdDbFile;
	}

	public String getSdDefaultXml() {
		return sdXmlDir + sdDefaultXml;
	}

	public String getSdRootDir() {
		return sdRootDir;
	}

	public String getSdXmlDir() {
		return sdXmlDir;
	}

	private void init() {
		player = new MediaPlayer();
		if (Environment.MEDIA_MOUNTED.equals(Environment
				.getExternalStorageState())) {
			File sd = Environment.getExternalStorageDirectory();
			sdRootDir = sd.getPath();

			// create xml dir
			String temp = sdRootDir + "/ygstudio/xue/de/xml";
			File xmlDir = new File(temp);
			if (!xmlDir.exists()) {
				if (xmlDir.mkdirs()) {
					sdXmlDir = temp;
				}
			} else {
				sdXmlDir = xmlDir.getPath();
			}

			// create mp3 dir
			temp = sdRootDir + "/ygstudio/xue/de/mp3";
			File mp3Dir = new File(temp);
			if (!mp3Dir.exists()) {
				if (mp3Dir.mkdirs()) {
					sdMp3Dir = temp;
				}
			} else {
				sdMp3Dir = mp3Dir.getPath();
			}

			// create db dir
			temp = sdRootDir + "/ygstudio/xue/de/db";
			File dbDir = new File(temp);
			if (!dbDir.exists()) {
				if (dbDir.mkdirs()) {
					sdDbDir = temp;
				}
			} else {
				sdDbDir = temp;
			}

			if (sdDbDir != null) {
				sdDbFile = sdDbDir + "/main.db";
			}
		}
	}

	public String getSdMp3Dir() {
		return sdMp3Dir;
	}

	public void Search() {

	}

	public void setMainContext(Context context) {
		this.context = context;
	}

	public MediaPlayer getMediaPlayer() {
		return player;
	}

}
